package com.xhj.joffer.linkedList;
import org.junit.Test;

import java.util.HashMap;
/**
 * @author haijianxia pure_xhj@163.com
 * @Date 2021-09-17
 * @Time 17:41
 */
public class LinkedListNodeOne {
	Object value;
	LinkedListNodeOne next;
	public LinkedListNodeOne() {
	}
	public LinkedListNodeOne(Object value) {
		this.value = value;
	}
	public LinkedListNodeOne(Object value, LinkedListNodeOne next) {
		this.value = value;
		this.next = next;
	}
	public LinkedListNodeOne(Object value, LinkedListNodeOne prev, LinkedListNodeOne next) {
		this.value = value;
		this.next = next;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	public LinkedListNodeOne getNext() {
		return next;
	}
	public void setNext(LinkedListNodeOne next) {
		this.next = next;
	}
	public LinkedListNodeOne next(LinkedListNodeOne next) {
		this.next = next;
		return next;
	}
	@Override
	public String toString() {
		return ""
			+"\tvalue: "+value==null?"":value.toString()
//			+"\tprev: "+prev==null?"":prev.getValue()==null?"":prev.getValue().toString()
//			+"\tnext: "+next==null?"":next.getValue()==null?"":next.getValue().toString()
			;
	}

	public String toStringTail(){
		String str=value.toString();
		LinkedListNodeOne nodeTemp = next;
		HashMap<LinkedListNodeOne,Integer> hashMap=new HashMap<>();
		while (nodeTemp != null) {
			if(hashMap.containsKey(nodeTemp)){
				break;
			}
			hashMap.put(nodeTemp,1);
      str+=(" --> "+nodeTemp.getValue().toString());
      nodeTemp=nodeTemp.next;
    }
		return str;
	}

}
